package org.admin.controller;

import core.Data;
import core.data.DataResult;
import org.admin.entity.dto.PowerDto;
import org.admin.service.PowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/role/power")
public class RolePowerController {
    @Autowired
    private PowerService service;
    @PostMapping("/update")
    public DataResult update(@RequestBody Map<String, Object> post){
        return Data.create(post)
                .<PowerDto>addHandle("params", data -> {
                    new PowerDto().validate(new String[] {
                        "powers", "*roleId"
                    }).check(data);
                }).addHandle("update", service::update)
                .start().getResult();
    }
    @GetMapping("/list")
    public DataResult list(@RequestParam Map<String, Object> get){
        return Data.create(get)
                .<PowerDto>addHandle("params", data -> {
                    new PowerDto().validate(new String[] {
                            "roleId",
                    }).check(data);
                }).addHandle("list", service::list)
                .start().getResult();
    }





}
